import { Controller, Get, Delete, Param, Query, Body, Put } from '@nestjs/common';
import { LikeService } from './like.service';
import { Like } from '../../entities/like.entity';
import { Admin } from '../../common/decorators/admin.decorator';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiParam, ApiQuery } from '@nestjs/swagger';

@ApiTags('点赞管理（管理员）')
@Controller('api/admin/likes')
export class LikeAdminController {
  constructor(private readonly likeService: LikeService) {}

  // 获取所有点赞记录（管理员）
  @Admin()
  @Get()
  @ApiOperation({
    summary: '获取所有点赞记录',
    description: '管理员获取系统中的所有点赞记录，支持分页和筛选',
  })
  @ApiQuery({
    name: 'page',
    description: '页码',
    example: 1,
    required: false,
  })
  @ApiQuery({
    name: 'pageSize',
    description: '每页数量',
    example: 10,
    required: false,
  })
  @ApiQuery({
    name: 'articleId',
    description: '文章ID（可选）',
    required: false,
  })
  @ApiQuery({
    name: 'userId',
    description: '用户ID（可选）',
    required: false,
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: [Like],
  })
  @ApiResponse({
    status: 403,
    description: '无管理员权限',
  })
  findAllAdmin(
    @Query('page') page: number = 1,
    @Query('pageSize') pageSize: number = 10,
    @Query('articleId') articleId?: number,
    @Query('userId') userId?: number
  ) {
    return this.likeService.findAllAdmin(page, pageSize, articleId, userId);
  }

  // 获取文章的点赞列表（管理员）
  @Admin()
  @Get('article/:articleId')
  @ApiOperation({
    summary: '获取文章点赞列表',
    description: '管理员获取指定文章的所有点赞用户信息',
  })
  @ApiParam({
    name: 'articleId',
    description: '文章ID',
    example: '1',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: [Like],
  })
  @ApiResponse({
    status: 403,
    description: '无管理员权限',
  })
  @ApiResponse({
    status: 404,
    description: '文章不存在',
  })
  getArticleLikes(@Param('articleId') articleId: number) {
    return this.likeService.getArticleLikes(articleId);
  }

  // 获取点赞详情（管理员）
  @Admin()
  @Get(':id')
  @ApiOperation({
    summary: '获取点赞详情',
    description: '管理员获取指定点赞记录的详细信息',
  })
  @ApiParam({
    name: 'id',
    description: '点赞记录ID',
    example: '1',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: Like,
  })
  @ApiResponse({
    status: 403,
    description: '无管理员权限',
  })
  @ApiResponse({
    status: 404,
    description: '点赞记录不存在',
  })
  findOneAdmin(@Param('id') id: number) {
    return this.likeService.findOneAdmin(id);
  }

  // 删除点赞记录（管理员）
  @Admin()
  @Delete(':id')
  @ApiOperation({
    summary: '删除点赞记录',
    description: '管理员删除指定的点赞记录',
  })
  @ApiParam({
    name: 'id',
    description: '点赞记录ID',
    example: '1',
  })
  @ApiResponse({
    status: 200,
    description: '删除成功',
  })
  @ApiResponse({
    status: 403,
    description: '无管理员权限',
  })
  @ApiResponse({
    status: 404,
    description: '点赞记录不存在',
  })
  remove(@Param('id') id: number) {
    return this.likeService.remove(id);
  }

  // 批量操作点赞记录
  @Admin()
  @Put('batch-operate')
  @ApiOperation({
    summary: '批量操作点赞记录',
    description: '管理员批量删除点赞记录',
  })
  @ApiBody({
    schema: {
      example: {
        ids: [1, 2, 3],
        action: 'delete', // delete 删除
      },
    },
  })
  @ApiResponse({
    status: 200,
    description: '操作成功',
  })
  @ApiResponse({
    status: 403,
    description: '无管理员权限',
  })
  batchOperate(@Body('ids') ids: number[], @Body('action') action: string) {
    return this.likeService.batchOperate(ids, action);
  }
}